var iG = {};
/* 操作日期
---------------------------------------------------------------------------------------*/
//获取年
iG.getYear = function(date){
    if(date == undefined) date = new Date;
    return date.getFullYear();
};
//获取月
iG.getMonth = function(date){
    if(date == undefined) date = new Date;
    var month = date.getMonth() + 1;
    if(month < 10) month = "0" + month;
    return month;
};
//获取日
iG.getDay = function(date){
   if(date == undefined) date = new Date;
    var day = date.getDate();
    if(day < 10) day = "0" + day;
    return day;
};
//获取当前日期
iG.getDateToday = function(date){
    return iG.getYear() + "-" + iG.getMonth() + "-" + iG.getDay();
};
//获取星期
iG.getWeek = function(date){
    if(date == undefined) date = new Date;
    var week = date.getDay();
    var weekArr = ["日","一","二","三","四","五","六"];
    return weekArr[week];
};
//获取小时
iG.getHours = function(date){
    if(date == undefined) date = new Date;
    return date.getHours();
},
//获取分钟
iG.getMinutes = function(date){
    if(date == undefined) date = new Date;
    return date.getMinutes();
};
//权限检查
iG.checkAuthortization = function(type,htmlName){
    var authorArr = iG.getObjItem("basicData","authorArr");
    if($.inArray(htmlName,authorArr) == -1){
        //alert(htmlName + " can not open");
        return false;
    }
    return true;
};
iG.bgm=function() {  
        var uid = localStorage['MU30-lOGIN-USRNAME'];
        var localstr = localStorage['MU30-userInfor-' + uid];
        if(localstr == undefined){
            return; 
        }
        var localstr=JSON.parse(localstr);
        var name=localstr.name;
        /*if (localstr.appPolicy == "联合办公帐号") {
            var name=localstr.name
        }else{
            var name=localstr.username
        }*/
        
        var canvas = document.getElementById('watermark')
           // var cw = $('#watermark');   
        var ctx = canvas.getContext("2d");   //返回一个用于在画布上绘图的环境
        ctx.clearRect(0,0,200,100);  //绘制之前画布清除
        ctx.font="20px 黑体";  
        ctx.rotate(-20*Math.PI/180);
        ctx.fillStyle = "rgba(0,0,0,0.1)";
        ctx.fillText(uid+'-'+name, -20, 80);     
        ctx.rotate('20*Math.PI/180');  //坐标系还原
        $('#repeat-watermark').css({  
                "position": "absolute",  
                "left": "0",  
                "top": "0",  
                "height": $(document).height(),  
                "opacity": "1",  
                "width": "100%",  
            });
        var crw = document.getElementById('repeat-watermark')
        crw.width = $(document).width();
        crw.height = $(document).height();
        ctxr = crw.getContext("2d");
        ctxr.clearRect(0,0,crw.width,crw.height);  //清除整个画布 
        var pat = ctxr.createPattern(crw, "repeat");    //在指定的方向上重复指定的元素  
        ctxr.fillStyle = pat;  
        ctxr.fillRect(0, 0, crw.width, crw.height);
        document.getElementById('repeat-watermark').style.backgroundImage = 'url("' + ctx.canvas.toDataURL() + '")';  
}
//数组去重
iG.unique3 = function(data){
 var res = [];
 var json = {};
 for(var i = 0; i < data.length; i++){
  if(!json[data[i]]){
   res.push(data[i]);
   json[data[i]] = 1;
  }
 }
 return res;
}
//debug
if(window.navigator.platform=="Win32" && iG.debug){
    document.write('<script src="../js/debug.js?v=202013"></script>')
};

//AJAX请求
iG.ajax = function(settings){
    var base64Encode = new Base64();
    //var url = "http://mobile-am.ceair.com:8080/AirMobileControlRS2/JsonService/";
  // if(this.debug) url = "http://mobile-amdev.ceair.com:8080/AirMobileControlRS2/JsonService/";
    var url = "http://mdmsys.ceair.com/AirMobileControlRS2/JsonService/";// UAT
    //url = "http://mobile-amdev.ceair.com:8080/AirMobileControlRS2/JsonService/";//测试
    var data = JSON.stringify(settings.data);
    var userInfo = iG.getUserInfo();
    var dataJson = {
        jsonStr : base64Encode.encode(data),
        jsonUserInfo : userInfo
    }
    $.ajax({
        type : "post",
        contentType: 'application/json',
        dataType:"json",
        url : url + "GetJsonDataPost?t="+new Date().getTime(),
        data: JSON.stringify(dataJson), 
        cache:false,
        success : function(data){
            try{
                settings.success(JSON.parse(data));
            }
            catch(e){
            }
        },
        error : function(data){ 
            settings.error(data);
        }
    });
};
//AJAX请求
iG.getAjax = function(settings){
//    var base64Encode = new Base64();
//    var url = "http://mobile-am.ceair.com:8088/mobileSecureR2/rest/querySecInfo";//生产
//    if(this.debug) url = "http://mobile-amdev.ceair.com:8088/mobileSecureR2/rest/querySecInfo";
    var url = "http://mdmsys.ceair.com/mobileSecureR2/rest/querySecInfo";//UAT
    //url = "http://mobile-amdev.ceair.com:8088/mobileSecureR2/rest/querySecInfo"; //测试
    var dataJson = {
        jsonStr : settings.data,
        jsonUserInfo : iG.getUserInfoStr()
    }
    var dataStr = JSON.stringify(dataJson);
    //alert(dataStr);
    console.log(dataStr)
    //dataStr='{"jsonStr":{"type":"83","condition":{"flightInfold":"99951332"}},"jsonUserInfo":{"a":"MOP","u":"kunguo","p":"ssap_0413!","m":"13122657175","t":"+8"}}';
    console.log(url+"?t="+new Date().getTime());
    console.log(dataStr);
    $.ajax({
        type : "post",
        contentType: 'application/json',
        dataType:"json",
        url : url+"?t="+new Date().getTime(),
        data: encode64(utf16to8(dataStr)), 
        cache:false,
        success : function(data){
            try{
                console.log(data)
                settings.success(data);
            }
            catch(e){   
            }
        },
        error : function(data){
            settings.error(data);
        }
    });
};
iG.getError = function(data,tipId){
    $.iBoxHide();
    if(data.readyState == 0 && data.statusText == "timeout"){
        iG.tip("很抱歉,无法连接服务器，请返回再试",tipId);
        return false;   
    }else if(data.readyState == 0 && data.statusText == "error"){
        iG.tip("很抱歉,获取数据失败，请检查网络是否正常！",tipId);
        return false;   
    }else{
        iG.tip("很抱歉,发现未知错误",tipId);
        return false;   
    }   
}
iG.getUserInfoStr = function(){ 
    var user = {
        "u": iG.getObjItem("LoginInforAMC","userCode"),
        "p": iG.getObjItem("LoginInforAMC","password"),
        "m": iG.getObjItem("LoginInforAMC","mobile"),
        "t": iG.getObjItem("LoginInforAMC","myTimezone"),
        "a": "MOP"
    };
    return user;
};